<?php

namespace app\providers\middleware;

use auth\Action;
use base\BaseMethod;
use app\admin\model\SystemParamValue;
use think\facade\View;
use think\facade\Env;


/**
 * 基础信息中间件
 * @package app\http\middleware
 */
class WebBaseConfig
{
	//自执行中间件方法
	public function handle($request, \Closure $next)
	{

		// if( !file_exists( root_path().'/public/admins/views/system/baseInstall/insall.lock' ) ){
		// 	die('需要先在根目录中，命令行执行命令:  php think views:link  ');
		// }

		//如果未初始化 - 跳转只初始化页面
		if (!file_exists(root_path() . '/views/system/baseInstall/insall.lock')) {
			if ($request->pathinfo() != "soft.install") {
				die(View::fetch('/system/baseInstall/index'));
			}
		}

		// 给值
		if ($host = $request->header('host')) {
			if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443')) {
				$scheme = 'https';
			} else {
				$scheme = 'http';
			}
			Env::set('APP_HOST', $scheme . '://' . $host);
		}

		return $next($request);
	}
}
